POV-Ray : Newsgroups : povray.programming : C++ problem : Re: C++ problem Server Time
28 Jul 2024 14:20:08 EDT (-0400)
  Re: C++ problem  
From: Warp
Date: 28 Jul 2001 16:41:56
Message: <3b632394@news.povray.org>
In povray.programming Thorsten Froehlich <tho### [at] trfde> wrote:
: I somehow get the impression you are not really sure what declarations do
: and don't do in C++ ...

  It's a surprisingly common phenomenon that people coding C++ don't really
know what type of code is generated from certain types of things.
  For example many people think that adding a function (ie. method) to a
class increases the size of the class. Although this misconception is
understandable, it's unfortunate, as it may lead to people trying to make
"size optimizations" where it doesn't have the slightest effect and only
makes the code worse.
  There are also other strange misconceptions. For example I have heard
people say that if you use one virtual function in a class, you should make
all functions virtual. I haven't the slightest clue what causes this
thinking, but it has to negative effects: It breaks object-orientedness
(by making functions virtual when they really shouldn't be) and it also
produces a bit slower code (calling a non-virtual function is a bit faster
than a virtual function; it doesn't matter if there are or aren't other
virtual functions in the same class).
  A related misconception is that calling a virtual function is very slow.
Yes, it's a bit slower than calling a regular function, but the speed
difference is usually one or two CPU clocks, which usually doesn't matter,
specially if the function itself takes hundreds of clocks.

  When people have many of these misconceptions and they try to "optimize"
they usually end up writing incredibly bad OO code in vain. They optimize
in really wrong places and make the code really bad.
  This is why it's important to know what type of code is generated from
what you write.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.